package com.bhs.sansonglogistics.ui.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.WaybillBean;
import com.bhs.sansonglogistics.utils.DateUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class WaybillAdapter extends BaseQuickAdapter<WaybillBean, BaseViewHolder> {

    private final int type;//1装车记录  2.运单查询 3.上游来货

    public WaybillAdapter(int type) {
        super(R.layout.item_waybill);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, WaybillBean item) {
        helper.addOnClickListener(R.id.btn_immediate_offer).addOnClickListener(R.id.btn_adjust);
        helper.setText(R.id.tv_license_plate_number, String.format("车牌号：%s", item.getLicense_plate()));
        helper.setText(R.id.tv_status, item.getStatus_msg());
        helper.setText(R.id.tv_waybill_number, String.format("运单号：%s", item.getWaybill_sn()));
        helper.setText(R.id.tv_order_number, String.format("订单数量：%s", item.getOrder_count()));
        helper.setText(R.id.tv_point_departure, item.getLine_start_city());
        helper.setText(R.id.tv_arrival_port, item.getLine_end_city());
        helper.addOnClickListener(R.id.tv_waybill_number);

        if (item.getStart_line_info() != null) {
            helper.setText(R.id.tv_shipping_company, String.format("发站公司：%s", item.getStart_line_info().getCompany_name()));
            helper.setText(R.id.tv_depart_phone_number, String.format("联系电话：%s", item.getStart_line_info().getLine_mobile()));
            helper.setText(R.id.tv_line_manager, String.format("线路经理：%s", item.getStart_line_info().getLine_contact()));
            helper.setText(R.id.tv_phone_number, String.format("手机号：%s", item.getStart_line_info().getLine_mobile()));
            helper.setText(R.id.tv_ship_address, String.format("发站地址：%s", item.getStart_line_info().getAddress()));
        }

        helper.setText(R.id.tv_arrive_company, String.format("到站公司：%s", item.getOutlets_name()));
        helper.setText(R.id.tv_arrive_phone_number, String.format("联系电话：%s", item.getOutlets_mobile()));


        helper.setText(R.id.tv_time, String.format("下单时间：%s", DateUtils.stampToDate(item.getCreate_time())));


        helper.setGone(R.id.btn_adjust, type == 3);
        helper.setGone(R.id.tv_line_manager, type == 2);
        helper.setGone(R.id.tv_phone_number, type == 2);
        helper.setGone(R.id.tv_ship_address, type == 2);
        helper.setGone(R.id.tv_depart_phone_number, type == 1 || type == 3);
        helper.setGone(R.id.tv_arrive_company, type == 1 || type == 3);
        helper.setGone(R.id.tv_arrive_phone_number, type == 1 || type == 3);
        helper.setGone(R.id.ll_operation, item.getStatus() == 0);
        helper.setGone(R.id.line, item.getStatus() == 0);


    }
}
